"use strict";


var wrapper = require('./apiwrapper')

wrapper.router.post('/reportTinkerInnerError', function (req, res) {
    var addSql = 'insert into tinkerlog (id,error_code,error_info,brand,model,os,os_alias,abi,create_time)' +
        ' values (?,?,?,?,?,?,?,?,?)'
    var addSqlParams = [
        wrapper.UUID.v1(),
        req.body.errorCode,
        req.body.errorInfo,
        req.body.brand,
        req.body.model,
        req.body.os,
        req.body.osAlias,
        req.body.abi,
        new Date().toFormat('YYYY-MM-DD HH24:MI:SS')
    ]
    wrapper.connection.query(addSql, addSqlParams, function (error, results) {
        if (!error) {
            var bizModel = wrapper.myUtils.generateSuccess()
            bizModel.model = {
                success: 0,
                info: '上传成功'
            }
            res.send(JSON.stringify(bizModel))
        } else {
            console.log(error)
            res.send(JSON.stringify(wrapper.myUtils.generateInnerError()))
        }
    })
})

wrapper.router.post('/reportlog', function (req, res) {
    var addSql = 'insert into patchlog (id,patch_md5,brand,model,os,os_alias,abi,error_info,error_code,create_time,logic_delete_flag)' +
        ' values (?,?,?,?,?,?,?,?,?,?,?)'
    var addSqlParams = [
        wrapper.UUID.v1(),
        req.body.md5,
        req.body.brand,
        req.body.model,
        req.body.os,
        req.body.osAlias,
        req.body.abi,
        req.body.errorInfo,
        req.body.errorCode,
        new Date().toFormat('YYYY-MM-DD HH24:MI:SS'),
        '01'
    ]
    wrapper.connection.query(addSql, addSqlParams, function (error, results) {
        if (!error) {
            var bizModel = wrapper.myUtils.generateSuccess()
            bizModel.model = {
                success: 0,
                info: '上传成功'
            }
            res.send(JSON.stringify(bizModel))
        } else {
            console.log(error)
            res.send(JSON.stringify(wrapper.myUtils.generateInnerError()))
        }
    })
})
wrapper.router.get('/getLogByMD5', function (req, res) {
    var searchSql = 'select * from patchlog where patch_md5 = ? and logic_delete_flag = 01'
    var searchSqlParams = [req.query.md5]
    wrapper.connection.query(searchSql, searchSqlParams, function (error, results) {
        if (!error) {
            var bizSucModel = wrapper.myUtils.generateSuccess()
            bizSucModel.model = {
                success: 0,
                patchlog: results
            }
            res.send(JSON.stringify(bizSucModel))
        } else {
            console.log(error)
            res.send(JSON.stringify(wrapper.myUtils.generateInnerError()))
        }
    })
})


module.exports = wrapper.router

